<template>
  <div>
    <div class="wrapper">
      <div class="userInput">
        <div class="inputBox">
          <x-input class="inputC" v-model="subObject.mobile" placeholder="请输入手机号码" :max="11" max-length="11" keyboard="number" is-type="china-mobile"></x-input>
        </div>
        <div class="inputBox">
          <x-input :show-clear="false" class="inputC inputCD" v-model="subObject.smsCode" placeholder="请输入验证码" ></x-input>
          <div class="forget" @click="getSmsCode">{{getVerify}}</div>
        </div>
        <div class="inputBox">
          <x-input class="inputC" type="password" v-model="subObject.newPasswrod" placeholder="请输入新密码" ></x-input>
        </div>
        <div class="inputBox">
          <x-input class="inputC" type="password" v-model="subObject.checkPasswrod" placeholder="请确认新密码" ></x-input>
        </div>
      </div>
      <div class="loginBtn" @click="login">
        确认
      </div>
    </div>
  </div>
</template>

<script>
import { mineApi } from '@/api'
export default {
  components: {
  },
  async created() {
    const inviteCode = this.$route.query.inviteCode
    this.inviteCode = inviteCode
    if (!inviteCode) {
      return
    }
    const res = await mineApi.getInfoByInviteCode(inviteCode)
    console.log('res', res)

    this.inviteInfo = res.data
    this.inviteInfo.HeadImg = this.inviteInfo.head_img
    this.inviteInfo.NickName = decodeURIComponent(this.inviteInfo.nickname)
    // this.inviteInfo.PersonalizedSignature = decodeURIComponent(this.inviteInfo.nickname)
  },
  data() {
    return {
      topResource: {
        centerCont: ''
      },
      getVerify: '获取验证码',
      subObject: {

      },
      inviteCode: '',
      inviteInfo: {}
    }
  },
  methods: {
    async getSmsCode() {
      if (this.getVerify !== '获取验证码' && this.getVerify !== '重新获取验证码') {
        return
      }
      if (!this.subObject.mobile || this.subObject.mobile.length < 11) {
        this.$toast('请输入正确的手机号')
        return
      }
      const res = await mineApi.getSms({
        mobile: this.subObject.mobile
      })
      if (res.code) {
        return
      }
      this.$toast('短信发送成功，请注意查收！')
      this.value = 60
      this.getVerify = this.value + 's后重发'
      var timers = setInterval(() => {
        this.value--
        this.getVerify = this.value + 's后重发'
        if (this.value <= 0) {
          clearInterval(timers)
          this.getVerify = '重新获取验证码'
        }
      }, 1000)
    },
    async login() {
      if (this.subObject.newPasswrod !== this.subObject.checkPasswrod) {
        console.log('newPasswrod')
        this.$toast('两次输入的密码不一致')
        return
      }
      const res = await mineApi.forgetPassword(this.subObject)
      // console.log('res', res.code)
      if (res.code) {
        return
      }
      this.$router.push('/login')
      console.log('login')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/assets/css/mixin.scss";
@import 'src/assets/css/variables.scss';
  .wrapper {
    position: fixed;
    left: 0;
    top: 0;
    background: #fff;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /*background-color: #000;*/
    display: flex;
    flex-direction: column;
    align-items: center;
    .userInput{
      padding: 10px 10px;
      width: 100%;
      .inputBox{
        position: relative;
        .iconC{
          position: absolute;
          width: 24px;
          top: 9px;
          left: 0;
        }
        .inputC{
          position: relative;
          border-top: none;
          border-bottom: 1px solid #ddd;
          &::before{
            border: none;
          }
        }
        .forget{
          color: $color-theme;
          position: absolute;
          right: 0;
          top: 0;
          line-height: 44px;
        }
      }
    }
    .loginBtn{
      margin-top: 20px;
      font-size: 16px;
      color: white;
      /* background: -webkit-linear-gradient(left, #A38456, #CABA96); */
      background-color: $color-theme;
      line-height: 41px;
      text-align: center;
      border-radius: 5px;
      width: 80%;
    }
    .toRegister{
      color: $color-theme;
      text-decoration: underline;
      margin-top: 15px;

    }
  }
</style>
